class ImageTranslateResponse {
  final bool success;
  final ImageTranslateResult result;
  final String logId;

  ImageTranslateResponse({
    required this.success,
    required this.result,
    required this.logId,
  });

  factory ImageTranslateResponse.fromJson(Map<String, dynamic> json) {
    return ImageTranslateResponse(
      success: json['success'] ?? false,
      result: ImageTranslateResult.fromJson(json['result'] ?? {}),
      logId: json['log_id'] ?? '',
    );
  }
}

class ImageTranslateResult {
  final String from;
  final String to;
  final String pasteImg;
  final String sumSrc;
  final String sumDst;
  final List<ImageContent> content;

  ImageTranslateResult({
    required this.from,
    required this.to,
    required this.pasteImg,
    required this.sumSrc,
    required this.sumDst,
    required this.content,
  });

  factory ImageTranslateResult.fromJson(Map<String, dynamic> json) {
    List<ImageContent> contentList = [];
    if (json['content'] != null && json['content'] is List) {
      contentList = (json['content'] as List)
          .map((item) => ImageContent.fromJson(item))
          .toList();
    }

    return ImageTranslateResult(
      from: json['from'] ?? '',
      to: json['to'] ?? '',
      pasteImg: json['pasteImg'] ?? json['paste_img'] ?? '',
      sumSrc: json['sumSrc'] ?? json['sum_src'] ?? '',
      sumDst: json['sumDst'] ?? json['sum_dst'] ?? '',
      content: contentList,
    );
  }
}

class ImageContent {
  final String src;
  final String dst;
  final String rect;
  final List<String> points;
  final String? pasteImg;

  ImageContent({
    required this.src,
    required this.dst,
    required this.rect,
    required this.points,
    this.pasteImg,
  });

  factory ImageContent.fromJson(Map<String, dynamic> json) {
    List<String> pointsList = [];
    if (json['points'] != null && json['points'] is List) {
      pointsList = (json['points'] as List).map((e) => e.toString()).toList();
    }

    return ImageContent(
      src: json['src'] ?? '',
      dst: json['dst'] ?? '',
      rect: json['rect'] ?? '',
      points: pointsList,
      pasteImg: json['pasteImg'] ?? json['paste_img'],
    );
  }
}